package com.east.service.fee.impl;

import java.util.Date;
import java.util.UUID;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.east.bean.Fee;
import com.east.bean.Income;
import com.east.dao.IncomeMapper;
import com.east.service.fee.IncomeService;
import com.east.utils.DateUtils;
import com.east.utils.Pagenation;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
@Service("incomeService")
public class IncomeServiceImpl implements IncomeService{
	@Autowired
	IncomeMapper incomeMapper;
	@Override
	public Page<Income> findByPage(Pagenation pagenation, String key,String startTime ,String endTime) {
		Page<Income> startPage = PageHelper.startPage(pagenation.getPageNum(), pagenation.getPageSize());
		if(StringUtils.isBlank(endTime)) {
			endTime= DateUtils.getDaysOfDate(new Date());
		}
		incomeMapper.findbyIcomeAll(key,startTime,endTime);
		return startPage;
	}

	@Override
	public boolean saveIncome(Income income) {
		Income in = new Income();
		in.setIcMoneys(income.getIcMoneys());//收入金额
		in.setIcName(income.getIcName());//收入名称
		in.setIcRemark(income.getIcRemark());//备注
		in.setIcUnit(income.getIcUnit());//付款單位
		if(StringUtils.isNotBlank(income.getDateTime())) {
			in.setIcTime(DateUtils.getDate(income.getDateTime()));//收款时间
		}
		in.setIcType(income.getIcType());//类型
		int insert = incomeMapper.insert(in);
		if(insert>0) {
			return true;
		}
		return false;
	}

	@Override
	public boolean updateIncome(Income income) {
		
		Income in = incomeMapper.selectByPrimaryKey(income.getIcId());
		in.setIcMoneys(income.getIcMoneys());//收入金额
		in.setIcName(income.getIcName());//收入名称
		in.setIcUnit(income.getIcUnit());//付款單位
		in.setIcRemark(income.getIcRemark());//备注
		if(StringUtils.isNotBlank(income.getDateTime())) {
			in.setIcTime(DateUtils.getDate(income.getDateTime()));//收款时间
		}
		in.setIcType(income.getIcType());//类型
		int insert = incomeMapper.updateByPrimaryKey(in);
		if(insert>0) {
			return true;
		}
		return false;
	}

	@Override
	public boolean delIncome(Income income) {
		int deleteByPrimaryKey = incomeMapper.deleteByPrimaryKey(income.getIcId());
		if(deleteByPrimaryKey>0) {
			return true;
		}
		return false;
	}

	@Override
	public Income findByOne(Income income) {
		return incomeMapper.selectByPrimaryKey(income.getIcId());
	}

}
